using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class PatientMap : EntityTypeConfiguration<Patient>
	{
		public PatientMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.MedicalRecordNumber)
				.HasMaxLength(20);
				
			this.Property(t => t.FirstName)
				.IsRequired()
				.HasMaxLength(15);
				
			this.Property(t => t.MiddleName)
				.HasMaxLength(15);
				
			this.Property(t => t.LastName)
				.HasMaxLength(15);
				
			this.Property(t => t.Birthplace)
				.HasMaxLength(50);
				
			this.Property(t => t.IdentityCardbNumber)
				.HasMaxLength(30);
				
			this.Property(t => t.PhoneNumber)
				.HasMaxLength(20);
				
			this.Property(t => t.Email)
				.HasMaxLength(50);
				
			this.Property(t => t.CreatedBy)
				.HasMaxLength(50);
				
			this.Property(t => t.ModifiedBy)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("Patients");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.MedicalRecordNumber).HasColumnName("MedicalRecordNumber");
			this.Property(t => t.FirstName).HasColumnName("FirstName");
			this.Property(t => t.MiddleName).HasColumnName("MiddleName");
			this.Property(t => t.LastName).HasColumnName("LastName");
			this.Property(t => t.GenderId).HasColumnName("GenderId");
			this.Property(t => t.Birthdate).HasColumnName("Birthdate");
			this.Property(t => t.Birthplace).HasColumnName("Birthplace");
			this.Property(t => t.IdentityCardTypeId).HasColumnName("IdentityCardTypeId");
			this.Property(t => t.IdentityCardbNumber).HasColumnName("IdentityCardbNumber");
			this.Property(t => t.SalutationId).HasColumnName("SalutationId");
			this.Property(t => t.BloodTypeId).HasColumnName("BloodTypeId");
			this.Property(t => t.PhoneNumber).HasColumnName("PhoneNumber");
			this.Property(t => t.Email).HasColumnName("Email");
			this.Property(t => t.Weight).HasColumnName("Weight");
			this.Property(t => t.Height).HasColumnName("Height");
			this.Property(t => t.MaritalId).HasColumnName("MaritalId");
			this.Property(t => t.EthnicityId).HasColumnName("EthnicityId");
			this.Property(t => t.RecordStatus).HasColumnName("RecordStatus");
			this.Property(t => t.CreatedBy).HasColumnName("CreatedBy");
			this.Property(t => t.CreatedOn).HasColumnName("CreatedOn");
			this.Property(t => t.ModifiedBy).HasColumnName("ModifiedBy");
			this.Property(t => t.ModifiedOn).HasColumnName("ModifiedOn");
			this.Property(t => t.ReligionId).HasColumnName("ReligionId");
			this.Property(t => t.IsTreated).HasColumnName("IsTreated");
			this.Property(t => t.OccupationId).HasColumnName("OccupationId");
			this.Property(t => t.EducationId).HasColumnName("EducationId");

			// Relationships
			this.HasRequired(t => t.RefGender)
				.WithMany(t => t.Patients)
				.HasForeignKey(d => d.GenderId);
				
			this.HasOptional(t => t.RefIdentityCardType)
				.WithMany(t => t.Patients)
				.HasForeignKey(d => d.IdentityCardTypeId);
				
			this.HasOptional(t => t.RefEducation)
				.WithMany(t => t.Patients)
				.HasForeignKey(d => d.EducationId);
				
			this.HasOptional(t => t.RefEthnicity)
				.WithMany(t => t.Patients)
				.HasForeignKey(d => d.EthnicityId);
				
			this.HasOptional(t => t.RefMarital)
				.WithMany(t => t.Patients)
				.HasForeignKey(d => d.MaritalId);
				
			this.HasOptional(t => t.RefOccupation)
				.WithMany(t => t.Patients)
				.HasForeignKey(d => d.OccupationId);
				
			this.HasOptional(t => t.RefReligion)
				.WithMany(t => t.Patients)
				.HasForeignKey(d => d.ReligionId);
				
			this.HasOptional(t => t.RefType)
				.WithMany(t => t.Patients)
				.HasForeignKey(d => d.BloodTypeId);
				
			this.HasOptional(t => t.RefSalutation)
				.WithMany(t => t.Patients)
				.HasForeignKey(d => d.SalutationId);
				
		}
	}
}

